package fr.emn.integration.synthese.controle;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.presentation.AjoutEncadrantDialog;

public class ControlJButtonSaveEncadrant implements ActionListener{
	
	private Cours modele;
	private AjoutEncadrantDialog parent;


	public ControlJButtonSaveEncadrant(Cours modele, AjoutEncadrantDialog parent) {
		super();
		this.modele = modele;
		this.parent = parent;
	}



	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(parent.getNom()!=null && parent.getPrenom()!=null && parent.getMail()!=null){
			try {
				modele.saveEncadrant(parent.getNom(), parent.getPrenom(), parent.getMail());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		else {
			JOptionPane.showMessageDialog(parent, "Un champ est vide !", "Erreur!",
					JOptionPane.ERROR_MESSAGE);
		}
		parent.setVisible(false);
	}

}
